import {service as request} from '@/utils/request'

/**
 * 多条件分页查询主机监控数据
 * @param {*} data 
 * @returns 
 * 12.10
 */
export function getList(data) {
  return request({
    url: `/hawk/hosts/monitor/search/${data.page.current}/${data.page.size}`,
    method: 'get',
    params:data.query
  })
}

/**
 * 
 * @param {*} data 
 * @returns 
 */
export function getItemList(data) {
  return request({
    url: `/hawk/items/search/${data.page.current}/${data.page.size}`,
    method: 'get',
    params:data.query
  })
}


/**
 * 判断对应的 key 的条目是否布在
 * @param {*} data 
 * @returns 
 */
export function isHaveItem(data) {
  return request({
    url: `/hawk/items/exists`,
    method: 'post',
    data: {
      "hostId": data.hostId,
      "key": data.key
    },
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}




export function syncItem(id) {
  return request({
    url: `/monitor/item/info/sync/${id}`,
    method: 'get'
  })
}
export function templateList() {
  return request({
    url: `/monitor/item/key`,
    method: 'get'
  })
}

export function searchList(data) {
  return request({
    url: `/monitor/item/page/${JSON.stringify(data)}`,
    method: 'get'
  })
}
/**
 * 新增监控项
 * @param {*} data 
 * @returns 
 * 14.4
 */
export function doAdd(data) {
  return request({
    url: '/hawk/items/save',
    method: 'post',
    data
  })
}



export function doEdit(data) {
  return request({
    url: '/hawk/items/update',
    method: 'put',
    data
  })
}
export function doDelete(ids) {
  return request({
    url: `/hawk/items/del`,
    method: 'delete',
    data:ids
  })
}
export function getOne(id) {
  return request({
    url: `/monitor/item/detail/${id}`,
    method: 'get'
  })
}
export function getAll() {
  return request({
    url: `/monitor/config/item`,
    method: 'get'
  })
}
export function separateItem(data){
  return request({
    url: '/monitor/config/item/separate',
    method: 'put',
    data
  })
}

/**
 * 获得所有的 key 
 * @returns 
 * 
 */
export function getAllKeys(){
  return request({
    url: '/hawk/keys/get/all',
    method: 'get',
  })
}
